//
//  YYEAnswerTableViewCell.m
//  YuYingEDU
//
//  Created by 胡波 on 2018/1/4.
//  Copyright © 2018年 胡波. All rights reserved.
//

#import "YYEAnswerTableViewCell.h"

@interface YYEAnswerTableViewCell ()

@property (nonatomic,strong) UIImageView *backIV;
@property (nonatomic,strong) UILabel *questionLabel;
@property (nonatomic,strong) UILabel *nameLabel;
@property (nonatomic,strong) UILabel *timeLabel;
@property (nonatomic,strong) UILabel *answerNameLabel;
//@property (nonatomic,strong) UILabel *answerLabel;

@end

@implementation YYEAnswerTableViewCell

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
     
        self.contentView.backgroundColor = GeneralBackColor;
        
        self.backIV = [[UIImageView alloc]init];
        self.backIV.image = [UIImage imageNamed:@"noBorder"];
        [self.contentView addSubview:self.backIV];
        
        self.timeLabel = [[UILabel alloc] init];
        self.timeLabel.textColor = LineColor;
        self.timeLabel.font = [UIFont systemFontOfSize:12];
        [self.backIV addSubview:self.timeLabel];
        
        self.nameLabel = [[UILabel alloc]init];
        self.nameLabel.textColor = [UIColor blackColor];
        self.nameLabel.font = [UIFont systemFontOfSize:14];
        [self.backIV addSubview:self.nameLabel];
        
        self.questionLabel = [[UILabel alloc]init];
        self.questionLabel.textColor = [UIColor blackColor];
        self.questionLabel.font = [UIFont systemFontOfSize:14];
        [self.backIV addSubview:self.questionLabel];
        
        self.answerNameLabel = [[UILabel alloc]init];
//        self.answerNameLabel.textColor = GeneralBlueColor;
        self.answerNameLabel.font = [UIFont systemFontOfSize:13];
        [self.backIV addSubview:self.answerNameLabel];
        
//        self.answerLabel = [[UILabel alloc]init];
//        self.answerLabel.textColor = [UIColor blackColor];
//        self.answerLabel.font = [UIFont systemFontOfSize:13];
//        [self.backIV addSubview:self.answerLabel];
        
//        self.questionLabel.text = @"为啥我这里没能实现功能？";
//        self.nameLabel.text = @"Jolin";
//        self.timeLabel.text = @"2017.7.23";
//        self.answerNameLabel.text = @"陈晨讲师的回答";
//        self.answerLabel.text = @"直接运行实现不了，用debug运行~";
        
    }
    return self;
    
}

- (void)layoutSubviews {
    [super layoutSubviews];
    
    [self.backIV makeConstraints:^(MASConstraintMaker *make) {
        make.edges.equalTo(UIEdgeInsetsMake(0, 8, 0.5, 8));
    }];
    
    [self.timeLabel makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(self.backIV.right).offset(-8);
        make.top.equalTo(self.backIV.top).offset(10);
    }];
    
    [self.nameLabel makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(self.timeLabel.left).offset(-16);
        make.top.equalTo(self.backIV.top).offset(10);
    }];
    
    [self.questionLabel makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.backIV.left).offset(15);
        make.top.equalTo(self.backIV.top).offset(10);
    }];
    
    [self.answerNameLabel makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.backIV.left).offset(10);
        make.right.equalTo(self.backIV.right).offset(-10);
//        make.top.equalTo(self.questionLabel.bottom).offset(10);
        make.bottom.equalTo(self.backIV.bottom).offset(-10);
    }];
    
//    [self.answerLabel makeConstraints:^(MASConstraintMaker *make) {
//        make.right.equalTo(self.backIV.right).offset(-10);
//        make.left.equalTo(self.answerNameLabel.right);
//        make.bottom.equalTo(self.backIV.bottom).offset(-10);
//    }];
    
}

- (void)setAnswerModel:(YYELessonAnswerModel *)answerModel {
    _answerModel = answerModel;
    
    self.questionLabel.text = answerModel.question;
    self.nameLabel.text = answerModel.student_name;
    self.timeLabel.text = answerModel.que_created_at;
    if (answerModel.teacher_name.length > 0) {
//        self.answerNameLabel.text = [NSString stringWithFormat:@"%@的回答：",answerModel.teacher_name];
        NSString *answerStr = [NSString stringWithFormat:@"%@的回答：",answerModel.teacher_name];
        NSMutableAttributedString *attr = [[NSMutableAttributedString alloc]initWithString:[NSString stringWithFormat:@"%@%@",answerStr,answerModel.answer]];
        [attr addAttribute:NSForegroundColorAttributeName value:[UIColor blueColor] range:NSMakeRange(0, answerStr.length)];
        [attr addAttribute:NSForegroundColorAttributeName value:[UIColor blackColor] range:NSMakeRange(answerStr.length, answerModel.answer.length)];
        self.answerNameLabel.attributedText = attr;
//        self.answerLabel.text = answerModel.answer;
    }else {
        self.answerNameLabel.text = @"暂无回答";
    }
    
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
